remove current_package from context
authorAndy Russell <arussell123@gmail.com>
Wed, 16 Nov 2016 19:31:06 +0000 (14:31 -0500)
committerAndy Russell <arussell123@gmail.com>
Thu, 8 Dec 2016 21:11:19 +0000 (16:11 -0500)
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_rustc/mod.rs

index de90ba89b260970b8bebadfd606cfd8ccab8e837..c53ce604072773505ca40269bcd02ffbe01be1bc 100644 (file)
@@ -29,9 +29,9 @@ pub struct Unit<'a> {
 }
 
 pub struct Context<'a, 'cfg: 'a> {
+    pub ws: &'a Workspace<'cfg>,
     pub config: &'cfg Config,
     pub resolve: &'a Resolve,
-    pub current_package: Option<PackageId>,
     pub compilation: Compilation<'cfg>,
     pub packages: &'a PackageSet<'cfg>,
     pub build_state: Arc<BuildState>,
@@ -60,7 +60,7 @@ struct TargetInfo {
 pub struct Metadata(u64);
 
 impl<'a, 'cfg> Context<'a, 'cfg> {
-    pub fn new(ws: &Workspace<'cfg>,
+    pub fn new(ws: &'a Workspace<'cfg>,
                resolve: &'a Resolve,
                packages: &'a PackageSet<'cfg>,
                config: &'cfg Config,
@@ -76,12 +76,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             None => None,
         };
 
-        let current_package = ws.current_opt().map(Package::package_id).cloned();
         Ok(Context {
+            ws: ws,
             host: host_layout,
             target: target_layout,
             resolve: resolve,
-            current_package: current_package,
             packages: packages,
             config: config,
             target_info: TargetInfo::default(),
@@ -450,8 +449,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         // we don't want to link it up.
         if src_dir.ends_with("deps") {
             // Don't lift up library dependencies
-            if self.current_package.as_ref().map_or(false, |p| unit.pkg.package_id() != p)
-                && !unit.target.is_bin() {
+            if self.ws.current_opt().map_or(false, |p| unit.pkg.package_id() != p.package_id())
+                    && !unit.target.is_bin() {
                 None
             } else {
                 Some((
@@ -837,7 +836,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     }
 
     pub fn show_warnings(&self, pkg: &PackageId) -> bool {
-        self.current_package.as_ref().map_or(false, |p| *pkg == *p)
+        self.ws.current_opt().map_or(false, |p| *pkg == *p.package_id())
             || pkg.source_id().is_path()
             || self.config.extra_verbose()
     }
index 6ddd002f84f0fcb1166830a5514850f50ecc6210..5e35a7e10306cc378ed11d1351af5760a41d308a 100644 (file)
@@ -198,8 +198,8 @@ impl<'a> JobQueue<'a> {
         }
 
         let build_type = if self.is_release { "release" } else { "debug" };
-        let profile = cx.current_package.as_ref().map_or_else(Profile::default, |p| {
-            cx.lib_profile(p).to_owned()
+        let profile = cx.ws.current_opt().map_or_else(Profile::default, |p| {
+            cx.lib_profile(p.package_id()).to_owned()
         });
         let mut opt_type = String::from(if profile.opt_level == "0" { "unoptimized" }
                                         else { "optimized" });
index 0abfe49865505b09635e259f819d7b3ddc53ef3a..dff80e493a7986d4eec1f98996ea4ce76e4bffef 100644 (file)
@@ -557,8 +557,8 @@ fn build_base_args(cx: &mut Context,
     let prefer_dynamic = (unit.target.for_host() &&
                           !unit.target.is_custom_build()) ||
                          (crate_types.contains(&"dylib") &&
-                          cx.current_package.as_ref().map_or(false, |p| {
-                              *p != *unit.pkg.package_id()
+                          cx.ws.current_opt().map_or(false, |p| {
+                              *p.package_id() != *unit.pkg.package_id()
                           }));
     if prefer_dynamic {
         cmd.arg("-C").arg("prefer-dynamic");